package com.myslef.teaching_platfrom.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.myslef.teaching_platfrom.domain.studentTak.StudentTask;
import com.myslef.teaching_platfrom.domain.studentTak.StudentTaskR;
import com.myslef.teaching_platfrom.domain.task.TaskR;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentTaskMapper extends BaseMapper<StudentTask> {

    @Select("\tSELECT t.*, COALESCE(st.status, 0)as `status` from  (select  t.* \n" +
            "\t\tfrom task t  join course c on t.course_id = c.id where course_id = #{classId}) t\n" +
            "\t\tleft join \n" +
            "\t\t(SELECT st.task_id,   status from student_task st " +
            "   WHERE st.student_id = #{studentId}) st on t.id = st.task_id order by t.deadline desc ")
    List<TaskR> getTaskLists(Integer classId, Integer studentId);


    @Select("SELECT st.id id, user_name , uid, st.update_time update_time, score, COALESCE(st.status, 0)  status from (SELECT u.id ,uid, user_name from user u\n" +
            "join student_course sc on u.id = sc.student_id\n" +
            "WHERE course_id = #{courseId}) stu " +
            "left JOIN (SELECT * FROM student_task " +
            "WHERE task_id = #{taskId}) st on st.student_id = stu.id")
    List<StudentTaskR> getStudentTaskList(Integer taskId, Integer courseId);



}
